#!/bin/bash
remote_path="temp/" # 上传默认的路径(Upload default path)
base_url="https://cdn.jsdelivr.net/gh/User/cdn@master/img/" # 自定义域名(Custom domain name)
push_path="D:\Github\cdn\img\\" # 末尾必须双斜杠(Must end with a double slash)

# 计算上传图片数量(Calculate the number of uploaded files)
for i in "$@"; do
    IFS='/' read -r -a array <<< "$i"
	id="${#array[@]}"
done
for l in "$@"; do
	# 开始填充URL(Start filling URL)
	current=`date "+%Y-%m-%d %H:%M:%S"`  
	timeStamp=`date -d "$current" +%s`   
	#将current转换为时间戳，精确到毫秒(Converted to a timestamp, accurate to milliseconds)
	currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) 
	# 获取后缀名(Get suffix)
	new_name=$currentTimeStamp.${i##*.}
	push_paths=$push_path$remote_path$currentTimeStamp.${i##*.}
	url="$base_url""$remote_path""$new_name"
	# 复制输出文件到指定地址(Copy the output file to the specified address)
    cp $i $push_paths
    # 复制链接到粘贴板(Copy link to pasteboard)
    echo "![image-"$currentTimeStamp"](""$url"")" | clip
    # TODO linux可以在这修改(Linux can be modified here)
done